// pages/mytrain/mytrain.js
var utils = require('../../utils/util.js');
var httpUrl = getApp().globalData.httpUrl;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        date: "",
        isfalse: true,
        isbut:false
    },
    bindDateChange: function(e) {
        this.setData({
            isfalse: false,
            date: e.detail.value
        })
        this.myTrainList(e.detail.value);
    },
    onLoad: function(options) {
        var that = this;
        that.setData({
            date: utils.formatData(new Date),
            date111: utils.formatData(new Date)
        })
        utils.showLoading();
        that.myTrainList(utils.formatData(new Date));
    },
    myTrainList: function(data) {
        var that = this;
        utils.http(httpUrl + "/mobile/member/my_train", {
            date: data
        }, function(res) {
            utils.hideLoading();
            if (res.state == 1) {
                that.setData({
                    list: res.datas
                });
            } else {
                utils.message(res.datas);
            }
        })
    },
    //实时获取input 数据
    oNbindInput:function(e){
        var that=this;
       that.setData({
           numInput:e.detail.value,
           isbut:true
       }) 
    },
    //保存
    onSaveTap: function(e) {
        var that = this;
            utils.http(httpUrl + "/mobile/member/add_train", {
                date: that.data.date,
                typeid: e.currentTarget.dataset.id,
                num: that.data.numInput
            }, function(res) {
                if (res.state == 1) {
                    that.setData({
                        list: res.datas,
                        isbut: false
                    });
                    wx.showToast({
                        title: '保存成功',
                    })
                    that.myTrainList(that.data.date);
                } else {
                    utils.message(res.datas);
                }
            })
     


    },
    //生成报表
    oNgenerateReportsTap: function(e) {
        wx.navigateTo({
            url: '../mytrain/ruleDesImg/ruleDesImg?typeid=' + e.currentTarget.dataset.typeid + "&date=" + this.data.date + "&name=" + e.currentTarget.dataset.name,
        })
    },
    //规则说明
    oNruleDescriptionTap: function(e) {
        wx.navigateTo({
            url: '../mytrain/ruleDescription/ruleDescription?rule=' + e.currentTarget.dataset.rule,
        })
    },
})